﻿using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System;

namespace Game.Level
{
    public class MilestoneEventArgs : EventArgs
    {
        public GameMilestone GameMilestone { get; set; }
    }

    [CollectionDataContract(Namespace = "game", ItemName = "Milestone")]
    public class GameMilestones : KeyedCollection<GameMilestoneType, GameMilestone>
    {
        public event EventHandler<MilestoneEventArgs> MilestoneAdded;

        public GameMilestones()
        {
        }

        protected override GameMilestoneType GetKeyForItem(GameMilestone item)
        {
            return item.EventType;
        }

        protected override void InsertItem(int index, GameMilestone item)
        {
            base.InsertItem(index, item);
            FireMilestoneAdded(item);
        }

        void FireMilestoneAdded(GameMilestone milestone)
        {
            if (MilestoneAdded != null)
            {
                MilestoneAdded(this, new MilestoneEventArgs() { GameMilestone = milestone });
            }
        }
    }
}
